﻿cmake_minimum_required(VERSION 3.10)

project(pingpong)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(Boost REQUIRED system)

find_package(Qt5 REQUIRED Network)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

set(ALL_SRCS
    "include/pingpong.h"
    "src/pingpong.cc"
    "src/pingpong_private.h"
    "src/pingpong_private.cc"
    "src/server_qt.h"
    "src/server_qt.cc"
    "src/client_qt.h"
    "src/client_qt.cc"
    "src/server_asio.h"
    "src/server_asio.cc"
    "src/client_asio.h"
    "src/client_asio.cc"
    "src/server_base.h"
    "src/server_base.cc"
    "src/client_base.h"
    "src/client_base.cc"
)

add_library(${PROJECT_NAME} SHARED ${ALL_SRCS})
target_include_directories(${PROJECT_NAME} PRIVATE ${Boost_INCLUDE_DIRS} include src)
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES} Qt5::Network)
target_compile_definitions(${PROJECT_NAME} PRIVATE BUILD_SHARED)

# 编译测试
option(BUILD_TEST "是否进行测试" OFF)

if (BUILD_TEST)
    find_package(GTest REQUIRED)
    add_executable(test src/main.cc)
    target_include_directories(test PRIVATE ${GTEST_INCLUDE_DIR} include)
    target_link_libraries(test PRIVATE ${GTEST_BOTH_LIBRARIES} ${PROJECT_NAME})

    add_test(NAME "${PROJECT_NAME}_test"
             COMMAND test.exe)
endif()